
def binary_search(arr, key):
    start = 0
    end = len(arr) - 1
    while start <= end:
        mid = int((start + end) / 2)
        if arr[mid] < key:
            start = mid + 1
        elif arr[mid] > key:
            end = end - 1
        else:
            return mid
    return -1


if __name__ == '__main__':
    matrix = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    key = 2
    print(binary_search(matrix, key))
